package com.bobi.ecofavor.model.dto;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.bobi.ecofavor.common.enums.CouponRangeEnum;
import com.bobi.ecofavor.common.enums.StoreCategoryEnum;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * @author wenyuan
 * @version 1.0
 * @date 2023/10/22
 * @since 8
 */
@Data
public class CouponDto implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "优惠券主键")
    private Integer id;

    @ApiModelProperty(value = "优惠券种类")
    private Integer couponCategoryId;

    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @ApiModelProperty(value = "起始时间")
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    private LocalDateTime beginTime;

    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @ApiModelProperty(value = "结束时间")
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    private LocalDateTime endTime;

    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @ApiModelProperty(value = "使用时间")
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    private LocalDateTime useTime;

    @ApiModelProperty(value = "用户")
    private Integer userId;

    @ApiModelProperty(value = "状态（未领取、待领取、待使用、已过期、已使用）")
    private Integer couponStatus;

    @ApiModelProperty(value = "优惠券名称")
    private String couponName;

    @ApiModelProperty(value = "作用范围（全平台、指定商户、指定分类））")
    private Integer useRange;

    @ApiModelProperty(value = "作用店铺分类（全平台是即为通用）")
    private Integer storeCategory;

    @ApiModelProperty(value = "店铺id")
    private Integer storeId;

    @ApiModelProperty(value = "优惠券标识")
    private String couponMark;

    @ApiModelProperty(value = "优惠条件")
    private Integer couponCondition;

    @ApiModelProperty(value = "要求金额")
    private BigDecimal requiredAmount;

    @ApiModelProperty(value = "减免金额")
    private BigDecimal cutAmount;

    @ApiModelProperty(value = "折扣大小")
    private BigDecimal discount;

    @ApiModelProperty(value = "领取后有效持续时间")
    private Integer validTime;


    /**
     * 根据 useRange storeCategory 得到优惠券标识
     * 只有当是 平台卷、或是分区卷才有
     */
    public void setCouponMark() {
        if (useRange == CouponRangeEnum.COMMON.getCode())
            couponMark = "通用";
        else if (useRange == CouponRangeEnum.CLASS.getCode()) {
            StoreCategoryEnum[] values = StoreCategoryEnum.values();
            for (StoreCategoryEnum value : values) {
                if (storeCategory == value.getCode())
                    couponMark = StoreCategoryEnum.FOOD.getDesc();
            }
        }
    }

}
